package com.tc.property.config.model;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ConfigContext implements Serializable {

	private static final long serialVersionUID = -2034591079178169505L;

	@Getter
	@Setter
	private Map<String, ConfigItem> contextItemMap = new ConcurrentHashMap<String, ConfigItem>();

	@Getter
	@Setter
	private Map<String, ConfigItem> cfgcenterItemMap = new ConcurrentHashMap<String, ConfigItem>();

	public void merge(Map<String, ConfigItem> contextItemMap) {
		this.contextItemMap.putAll(contextItemMap);
	}

	public void remove(String key) {
		try {
			contextItemMap.remove(key);
		} catch (Exception e) {
		}
	}

	public String get(String key) {
		ConfigItem item = getContextItem(key);
		if (item != null) {
			return item.getValue();
		}

		return null;
	}

	public ConfigItem getContextItem(String key) {
		return contextItemMap.get(key);
	}

}
